/*
 * Copyright 2019-2021 shoprh.com. All rights reserved.
 * Support: http://www.shoprh.com
 * License: http://www.shoprh.com/license
 */
package com.shoprh.shop.service.impl;

import java.util.List;

import cn.hutool.core.collection.CollUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shoprh.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.shoprh.shop.mapper.AdMapper;
import com.shoprh.shop.domain.Ad;
import com.shoprh.shop.service.IAdService;

/**
 * Service - 广告
 *
 * @author 若狐 Team
 * @version 1.0
 */
@Service
public class AdServiceImpl extends ServiceImpl<AdMapper, Ad> implements IAdService {
    @Autowired
    private AdMapper adMapper;

    /**
     * 查询广告
     *
     * @param id 广告ID
     * @return 广告
     */
    @Override
    public Ad selectAdById(Long id) {
        return adMapper.selectById(id);
    }

    /**
     * 查询广告列表
     *
     * @param ad 广告
     * @return 广告
     */
    @Override
    public List<Ad> selectAdList(Ad ad) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("a.delete_flag", 0);
        if (StringUtils.isNotEmpty(ad.getTitle())) {
            queryWrapper.like("a.title", ad.getTitle());
        }
        return adMapper.selectList(queryWrapper);
    }

    /**
     * 新增广告
     *
     * @param ad 广告
     * @return 结果
     */
    @Override
    public int insertAd(Ad ad) {
        return adMapper.insert(ad);
    }

    /**
     * 修改广告
     *
     * @param ad 广告
     * @return 结果
     */
    @Override
    public int updateAd(Ad ad) {
        return adMapper.updateById(ad);
    }

    /**
     * 删除广告对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteAdByIds(String ids) {
        return adMapper.deleteBatchIds(CollUtil.toList(ids));
    }

}
